<template>
    <div class="contentBox">

        <!--  @handle-reset="resetParams" @handle-search="getList" -->
        <SearchForm v-if="0">
            <!-- <template #header>
                <el-button @click="onAddOrUpdate()">新增子账号</el-button>
            </template> -->
            <el-form :model="searchForm" inline>
                <el-form-item>
                    <el-input v-model="searchForm.phone" clearable @change="getList" class="w-220px"
                        placeholder="手机号搜索" />
                </el-form-item>
                <el-form-item>
                    <el-input v-model="searchForm.userName" clearable @change="getList" class="w-220px"
                        placeholder="用户名搜索" />
                </el-form-item>
                <el-form-item>
                    <el-select v-model="searchForm.status" placeholder="类型" @change="getList" clearable class="w-220px">
                        <el-option label="全部" :value="0" />
                        <el-option label="已提现" :value="1" />
                        <el-option label="可提现" :value="2" />
                        <el-option label="待结算" :value="3" />
                        <el-option label="作废(用户退款)" :value="4" />
                    </el-select>
                </el-form-item>
            </el-form>
        </SearchForm>
        <div class="page-card h-full" v-loading="loading">
            <el-table :data="tableData">
                <el-table-column label="ID" prop="_id" align="center" />
                <el-table-column label="申请用户信息" align="left" width="200">
                    <template #default="scope">
                        <div>用户名:{{ scope.row.proxyUserId.userName }}</div>
                        <div>手机号:{{ scope.row.proxyUserId.phone }}</div>
                    </template>
                </el-table-column>
                <el-table-column label="提现金额" prop="applyMoney" align="center" />
                <el-table-column label="账户类型" align="center">
                    <template #default="scope">
                        <el-tag v-if="scope.row.binkType == 1" type="success">对公账户</el-tag>
                        <el-tag v-else>个人账户</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="名称" prop="userName" align="center" />
                <el-table-column label="纳税人识别号" prop="userNo" align="center" />
                <el-table-column label="开户行" prop="binkName" align="center" />
                <el-table-column label="银行账号" prop="binkNo" align="center" />
                <el-table-column label="手机号" prop="userPhone" align="center" />
                <el-table-column label="发票接收邮箱" prop="emaill" align="center" />

                <el-table-column label="状态" align="center">
                    <template #default="scope">
                        <el-tag v-if="scope.row.status == 0" type="success">待打款</el-tag>
                        <el-tag v-else-if="scope.row.status == 2" type="danger">已拒绝</el-tag>
                        <el-tag v-else type="warning">已提现</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="打款金额" prop="payMoney" align="center" />
                <el-table-column label="打款时间" prop="payTime" align="center" />

                <el-table-column label="创建时间" prop="createTime" align="center" />
                <el-table-column label="拒绝备注" prop="refuseRemark" align="center" />
                <el-table-column label="操作" align="center">
                    <template #default="scope">
                        <el-button type="text" @click="isforuserupdata(scope.row)"
                            :disabled="scope.row.status == 1 || scope.row.status == 2">已打款</el-button>
                        <el-button type="text" @click="jujueOpen(scope.row)"
                            :disabled="scope.row.status == 1 || scope.row.status == 2">拒绝</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { getuserPuterList, setMaPayStatus } from '@/api/orders';
import { useTable } from '@/hooks/useTable';
defineOptions({ name: 'TopCard' });
import { reactive } from "vue";
import { ElMessage, ElMessageBox } from 'element-plus'

const searchForm = reactive({
    phone: '',
    status: '',
    userName: ''
});
const { tableData, loading, getList, } =
    useTable({
        apiFn: getuserPuterList,
        params: searchForm
    });

function isforuserupdata(row: any) {
    console.log('提交已经打款的信息')
    setMaPayStatus({
        status: 1
    }, row._id,)
        .then((res) => {
            getList()
            ElMessage({
                type: 'success',
                message: '已完成打款， 业务完结',
            })
        })
}
function jujueOpen(row: any) {
    ElMessageBox.prompt('请输入拒绝原因', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消'
    })
        .then(({ value }) => {
            setMaPayStatus({

                status: 2,
                refuseRemark: value
            }, row._id,)
                .then((res) => {
                    getList()
                    ElMessage({
                        type: 'success',
                        message: '已拒绝',
                    })
                })
        })
        .catch(() => {

        })

}
</script>

<style lang="scss" scoped></style>